package de.koller.million.grid.frame;

import de.koller.million.grid.GNode;
import de.koller.million.grid.commands.AddGNode;
import de.koller.million.grid.frame.enc.EncStarterComp;
import de.koller.million.grid.frame.enc.EncounterFrame;
import de.koller.million.grid.frame.ply.PlayerFrameOpener;
import de.koller.million.grid.frame.plyManag.PlayerManagerFrame;

public class MainFrame extends GNode {
	
	private EncStarterComp encstarter = null;
	private EncounterFrame encframe = null;
	
	public MainFrameComp comp;
	
	@Override
	protected void init() {
		super.init();
		
		comp = new MainFrameComp( this );
		comp.setVisible( true );
	}

	@Override
	protected void release() {
		super.release();
		
		comp.dispose();
	}

	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
	
		comp.time.setText( groot.getTime() + "" );
		comp.playerNumber.setText( "Spieler: " + groot.engine.playerContainer.getPlayerNumber() );
	}
	
	public void openPlayerFrame( String name ) {
		groot.call( new PlayerFrameOpener( this, name ) );
	}

	public void openPlayerManager() {
		this.groot.call( new AddGNode( this, new PlayerManagerFrame() ) );
	}
	
	public void startEncounter() {
		if( groot.engine.getEncounter() == null ) {
			if( encstarter != null )
				encstarter.dispose();
			encstarter = new EncStarterComp( groot );
			encstarter.setVisible( true );
		} else
			showEncounter();
	}
	
	public void showEncounter() {
		if( encframe != null ) {
			encframe.comp.requestFocus();
			return;
		}
		encframe = new EncounterFrame( groot.engine.getEncounter() );
		groot.call( new AddGNode( groot.frame, encframe ) );
	}
	
	public void disShowEncounter() {
		encframe = null;
	}
	
	public void closeThis() {
		this.groot.stop();
	}
	
}
